Telegram Group & Telegram Channel
🤓 Как использовать концепты C++20 для создания надежного кода

Устали от непонятных ошибок шаблонов? Концепты спешат на помощь.

//  Старый подход без концептов
template<typename T>
T max_value(const std::vector<T>& values) {
// Ошибка будет обнаружена только при инстанциации шаблона
return *std::max_element(values.begin(), values.end());
}

// Современный подход с концептами
template<typename T>
requires std::totally_ordered<T>
T max_value(const std::vector<T>& values) {
return *std::max_element(values.begin(), values.end());
}

// Еще короче с auto
auto max_value(const std::vector<std::totally_ordered auto>& values) {
return *std::max_element(values.begin(), values.end());
}


❗️Преимущества:

- Более понятные сообщения об ошибках
- Документирование требований в коде
- Перегрузка на основе свойств типов

Встроенные концепты: std::integral, std::floating_point, std::copyable, std::same_as и другие.

Библиотека C/C++ разработчика
#буст
Please open Telegram to view this post
VIEW IN TELEGRAM



tg-me.com/cppproglib/5707
Create:
Last Update:

🤓 Как использовать концепты C++20 для создания надежного кода

Устали от непонятных ошибок шаблонов? Концепты спешат на помощь.

//  Старый подход без концептов
template<typename T>
T max_value(const std::vector<T>& values) {
// Ошибка будет обнаружена только при инстанциации шаблона
return *std::max_element(values.begin(), values.end());
}

// Современный подход с концептами
template<typename T>
requires std::totally_ordered<T>
T max_value(const std::vector<T>& values) {
return *std::max_element(values.begin(), values.end());
}

// Еще короче с auto
auto max_value(const std::vector<std::totally_ordered auto>& values) {
return *std::max_element(values.begin(), values.end());
}


❗️Преимущества:

- Более понятные сообщения об ошибках
- Документирование требований в коде
- Перегрузка на основе свойств типов

Встроенные концепты: std::integral, std::floating_point, std::copyable, std::same_as и другие.

Библиотека C/C++ разработчика
#буст

BY Библиотека C/C++ разработчика | cpp, boost, qt


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/cppproglib/5707

View MORE
Open in Telegram


Библиотека C C разработчика | cpp boost qt Telegram | DID YOU KNOW?

Date: |

Why Telegram?

Telegram has no known backdoors and, even though it is come in for criticism for using proprietary encryption methods instead of open-source ones, those have yet to be compromised. While no messaging app can guarantee a 100% impermeable defense against determined attackers, Telegram is vulnerabilities are few and either theoretical or based on spoof files fooling users into actively enabling an attack.

Telegram Auto-Delete Messages in Any Chat

Some messages aren’t supposed to last forever. There are some Telegram groups and conversations where it’s best if messages are automatically deleted in a day or a week. Here’s how to auto-delete messages in any Telegram chat. You can enable the auto-delete feature on a per-chat basis. It works for both one-on-one conversations and group chats. Previously, you needed to use the Secret Chat feature to automatically delete messages after a set time. At the time of writing, you can choose to automatically delete messages after a day or a week. Telegram starts the timer once they are sent, not after they are read. This won’t affect the messages that were sent before enabling the feature.

Библиотека C C разработчика | cpp boost qt from sg


Telegram Библиотека C/C++ разработчика | cpp, boost, qt
FROM USA